#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[]) {

    int n, m;
    scanf("%d %d", &n, &m);

    int numa[n], numb[m];

    for (size_t i = 0; i < n; i++)
    {
        scanf("%d", &numa[i]);
    }

    for (size_t i = 0; i < m; i++)
    {
        scanf("%d", &numb[i]);
    }

    int min = 9999;
    for (size_t i = 0; i < sizeof(numa)/sizeof(numa[0]); i++)
    {
        for (size_t z = 0; z < sizeof(numb)/sizeof(numb[0]); z++)
        {
            if(abs(numa[i]-numb[z])<min)
                min = abs(numa[i] - numb[z]);
        }
    }

    printf("%d", min);

    return 0;
}